cmath.phase(x)x 的相位角(即角度),範圍在 -π 到 π 之間。cmath.phase(x)
x (complex): 要計算相位角的複數。x 的相位角(弧度)。import cmath
x = 1 + 1j
print(cmath.phase(x)) # 輸出: 0.7853981633974483 (π/4)
cmath.polar(x)x 的極坐標形式,即半徑和相位角。cmath.polar(x)
x (complex): 要轉換為極坐標的複數。import cmath
x = 1 + 1j
print(cmath.polar(x)) # 輸出: (1.4142135623730951, 0.7853981633974483)
cmath.rect(r, phi)(r, phi) 對應的複數。cmath.rect(r, phi)
r (float): 複數的半徑(模)。phi (float): 複數的相位角(弧度)。import cmath
r, phi = 1.414, 0.785
print(cmath.rect(r, phi)) # 輸出: (1+1j)
cmath.exp(x)x 的指數函數,即 e**x。cmath.exp(x)
x (complex): 要計算指數函數的複數。e 的 x 次方的複數結果。import cmath
x = 1 + 1j
print(cmath.exp(x)) # 輸出: (1.4686939399158851+2.2873552871788423j)
cmath.log(x[, base])x 在指定基數下的對數,默認基數為 e。cmath.log(x[, base])
x (complex): 要計算對數的複數。base (float, 可選): 對數的基數,默認為 e。x 在指定基數下的對數。import cmath
x = 1 + 1j
print(cmath.log(x)) # 輸出: (0.34657359027997264+0.7853981633974483j)
print(cmath.log(x, 10)) # 輸出: (0.15082288918503002+0.34102985847404205j)